﻿@{
    Layout = null;

    Dictionary<string, string> typedic = ViewData["typedic"] as Dictionary<string, string>;
    DeliveryManage.Models.ReturnMsgModel returnMsg = ViewBag.ReturnMsgModel;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>菜单设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
    <link rel="stylesheet" href="~/Content/font.css">
    <link rel="stylesheet" href="~/Content/framemain.css">
    <script type="text/javascript" src="~/Content/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="~/Scripts/framemain.js"></script>
    <link rel="stylesheet" href="~/Content/roletree.css" />
    <link href="~/Content/icon/iconfont.css" rel="stylesheet" />

    <script type="text/javascript">
        function ExePostBack(objId) {
            var arr = $(".checkall");
            var ids = "";
            for (var i = 0; i < arr.length; i++) {
                if (arr[i].checked) {
                    ids += arr[i].parentElement.children[2].value + ",";
                }
            }
            if (ids.length < 1) {
                layer.alert('对不起，请选中您要操作的记录！', { icon: 2, title: '提示' }, function (index) {
                    layer.close();
                    return false;
                });
                return false;
            }
            var msg = "删除记录后不可恢复，您确定吗？";
            if (arguments.length == 2) {
                msg = objmsg;
            }
            layer.confirm(msg, { icon: 3, title: '提示' }, function (index) {
                $.ajax({
                    type: "POST",
                    url: "/System/SysNavigationDelete",
                    data: { id: ids },
                    success: function (obj) {
                        layer.alert(obj.msg, { icon: 6 }, function () {
                            if (obj.code == 200) {
                                layer.close();
                                location.reload();
                            }
                        });
                    }
                })
                layer.close();
            });
            return false;
        }

    $(function () {
            //操作提示
            if (@returnMsg.code == 400) {
                layer.msg('@returnMsg.msg', { icon: 5, title: '提示' }, function (index) {
                  layer.close();
                })
            }
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="javascript:;">首页</a>
                <a><cite>菜单设置</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        @{
            if (returnMsg.code == 200)
            {
                <div class="layui-fluid">
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-md12">
                            <div class="layui-card">
                                <div class="layui-card-header">
                                    <a title="是否添加父级菜单" class="layui-btn" onclick="xadmin.open('添加父级菜单','/System/SysParentEdit?action=Add&id=0',800,400)"><i class="layui-icon">&#xe61f;</i>添加父级菜单</a>
                                    <a title="是否添加子级菜单" class="layui-btn" onclick="xadmin.open('添加子级菜单','/System/SysNavigationEdit?action=Add&id=0',800,600)"><i class="layui-icon">&#xe61f;</i>添加子级菜单</a>
                                    <a title="是否删除菜单" id="btnDelete" class="layui-btn layui-btn-danger" onclick="ExePostBack(this);"><i class="layui-icon">&#xe640;</i>删除</a>
                                </div>
                                <div class="layui-card-body ">
                                    <table class="layui-table layui-form">
                                        <thead>
                                            <tr>
                                                <th>
                                                    <input type="checkbox" lay-filter="checkall" id="checkalll" name="checkalll" lay-skin="primary">
                                                </th>
                                                <th>菜单目录</th>
                                                <th>视图</th>
                                                <th>跳转链接</th>
                                                <th>排序</th>
                                                <th>操作权限</th>
                                                <th>状态</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody class="x-cate">
                                            @foreach (DeliveryManage.Model.Sys_Navigation item in ViewBag.NavigationList)
                                            {

                                                <tr cate-id='@item.id' fid='@item.parent_id'>
                                                    <td class="chkid">
                                                        <input type="checkbox" name="chkid" lay-skin="primary" class="checkall" />
                                                        <input type="hidden" name="hidid" value="@item.id" />
                                                    </td>
                                                    <td>


                                                        @{
                                                            if (item.parent_id == 0)
                                                            {
                                                                <a href="javascript:;">
                                                                    <i class="layui-icon @item.icon"></i>
                                                                    <cite>@item.sub_title</cite>
                                                                    <i class=" layui-icon x-show" style="float:right" status='false'>&#xe61a;</i>
                                                                </a>
                                                            }
                                                            else
                                                            {
                                                                <ul class="sub-menu">
                                                                    <li>
                                                                        <a href="#" onclick="xadmin.add_tab('@item.sub_title','')">
                                                                            <i class="layui-icon @item.icon" style="margin-left:10px;"></i>
                                                                            <cite>@item.sub_title</cite>
                                                                        </a>
                                                                    </li>
                                                                </ul>
                                                            }
                                                        }

                                                    </td>
                                                    <td>@item.name</td>
                                                    <td>@item.link_url</td>
                                                    <td>@item.sort_id</td>
                                                    <td>
                                                        @{
                                                            if (!string.IsNullOrEmpty(item.action_type))
                                                            {
                                                                string[] action_type = item.action_type.Split(',');

                                                                for (int i = 0; i < action_type.Count(); i++)
                                                                {
                                                                    <input type="checkbox" name="@typedic[action_type[i]]" lay-skin="primary" class="check" disabled="disabled" checked="checked" /><label class="lab" style="margin-right:15px;">@typedic[action_type[i]]</label>
                                                                }
                                                            }
                                                        }
                                                    </td>
                                                    <td>
                                                        <input type="checkbox" name="close" lay-skin="switch" lay-text="开启|关闭" disabled="disabled" @(item.is_lock == 0 ? "checked" : "")>
                                                    </td>
                                                    <td>
                                                        @{
                                                            if (item.parent_id == 0)
                                                            {
                                                                <a title="是否修改父级菜单" class="layui-btn layui-btn layui-btn-xs" onclick="xadmin.open('修改','/System/SysParentEdit?action=edit&id=@item.id',800,400)" href="javascript:;"><i class="layui-icon">&#xe642;</i>修改</a>
                                                            }
                                                            else
                                                            {
                                                                <a title="是否修改子级菜单" class="layui-btn layui-btn layui-btn-xs" onclick="xadmin.open('修改','/System/SysNavigationEdit?action=edit&id=@item.id',800,600)" href="javascript:;"><i class="layui-icon">&#xe642;</i>修改</a>
                                                            }
                                                        }
                                                    </td>
                                                </tr>

                                                }
                                            </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            }
        }

        <script type="text/javascript">
            layui.use(['laydate', 'form'], function () {
                var laydate = layui.laydate;
                var form = layui.form;
                // 监听全选
                form.on('checkbox(checkall)', function (data) {
                    if (data.elem.checked) {
                        $('tbody .chkid input').prop('checked', true);
                    } else {
                        $('tbody .chkid input').prop('checked', false);
                    }
                    form.render('checkbox');
                });
            });

            // 分类展开收起的分类的逻辑
            $(function () {

                $("tbody.x-cate tr[fid!='0']").show();

                // 栏目多级显示效果
                $('.x-show').click(function () {
                    if ($(this).attr('status') == 'true') {
                        $(this).html('&#xe61a;');
                        $(this).attr('status', 'false');
                        cateId = $(this).parents('tr').attr('cate-id');
                        $("tbody tr[fid=" + cateId + "]").show();
                    } else {
                        cateIds = [];
                        $(this).html('&#xe602;');
                        $(this).attr('status', 'true');
                        cateId = $(this).parents('tr').attr('cate-id');
                        getCateId(cateId);
                        for (var i in cateIds) {
                            $("tbody tr[cate-id=" + cateIds[i] + "]").hide().find('.x-show').html('&#xe602;').attr('status', 'true');
                        }
                    }
                })

            })

            var cateIds = [];
            function getCateId(cateId) {
                $("tbody tr[fid=" + cateId + "]").each(function (index, el) {
                    id = $(el).attr('cate-id');
                    cateIds.push(id);
                    getCateId(id);
                });
            }

        </script>
    </form>
</body>
</html>